/**
 * @file modernsnakeentrywidget.h
 * @brief 现代化Snake游戏入口界面 - 替代旧的游戏大厅
 */

#ifndef MODERNSNAKEENTRYWIDGET_H
#define MODERNSNAKEENTRYWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QTimer>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
#include <QParallelAnimationGroup>
#include <QGraphicsOpacityEffect>
#include <QGraphicsDropShadowEffect>
#include <QPainter>
#include <QPainterPath>
#include <QRandomGenerator>
#include <QMouseEvent>
#include <QEnterEvent>

/**
 * @class SnakePreviewWidget
 * @brief 蛇形预览组件 - 显示动态蛇形动画
 */
class SnakePreviewWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SnakePreviewWidget(QWidget *parent = nullptr);

protected:
    void paintEvent(QPaintEvent *event) override;

private slots:
    void updateAnimation();

private:
    QTimer *m_animationTimer;
    QList<QPointF> m_snakePoints;
    QList<QColor> m_snakeColors;
    float m_animationPhase;
    int m_direction;
    QPointF m_foodPosition;
    float m_foodGlow;
};

/**
 * @class ModernGameModeButton
 * @brief 现代化游戏模式按钮
 */
class ModernGameModeButton : public QPushButton
{
    Q_OBJECT

public:
    explicit ModernGameModeButton(const QString &title, const QString &subtitle, 
                                 const QString &icon, const QColor &color, QWidget *parent = nullptr);

    void setSelected(bool selected);
    bool isSelected() const { return m_selected; }

protected:
    void paintEvent(QPaintEvent *event) override;
    void enterEvent(QEnterEvent *event) override;
    void leaveEvent(QEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;

private:
    QString m_title;
    QString m_subtitle;
    QString m_icon;
    QColor m_color;
    bool m_selected;
    bool m_hovered;
    QPropertyAnimation *m_scaleAnimation;
    QGraphicsOpacityEffect *m_opacityEffect;
};

/**
 * @class ModernSnakeEntryWidget
 * @brief 现代化Snake游戏入口界面
 * 
 * 特色设计：
 * - 左侧：大型蛇形动画展示
 * - 右侧：现代化游戏模式选择
 * - 底部：玩家信息和控制按钮
 * - 全屏动态背景效果
 */
class ModernSnakeEntryWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ModernSnakeEntryWidget(QWidget *parent = nullptr);
    ~ModernSnakeEntryWidget();

    /**
     * @brief 设置玩家信息
     */
    void setPlayerInfo(const QString &playerId, const QString &playerName);

signals:
    /**
     * @brief 游戏模式选择信号
     */
    void gameModeSelected(const QString &gameMode);

    /**
     * @brief 返回主菜单信号
     */
    void backToMainMenu();

    /**
     * @brief 设置按钮点击信号
     */
    void settingsClicked();

protected:
    void paintEvent(QPaintEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;

private slots:
    // === 游戏模式选择 ===
    void onSinglePlayerClicked();
    void onMultiPlayerClicked();
    void onBattleRoyaleClicked();
    
    // === 控制按钮 ===
    void onBackToMenuClicked();
    void onSettingsClicked();
    
    // === 动画更新 ===
    void updateBackgroundAnimation();
    void startEntranceAnimations();

private:
    void setupUI();
    void setupStyles();
    void setupAnimations();
    void initializeParticles();
    void drawBackgroundEffects(QPainter &painter);

private:
    // === UI组件 ===
    QLabel *m_titleLabel;
    QLabel *m_subtitleLabel;
    SnakePreviewWidget *m_snakePreview;
    
    // === 游戏模式按钮 ===
    ModernGameModeButton *m_singlePlayerButton;
    ModernGameModeButton *m_multiPlayerButton;
    ModernGameModeButton *m_battleRoyaleButton;
    
    // === 控制按钮 ===
    QPushButton *m_backButton;
    QPushButton *m_settingsButton;
    QLabel *m_playerInfoLabel;
    
    // === 动画系统 ===
    QTimer *m_backgroundTimer;
    QSequentialAnimationGroup *m_entranceAnimations;
    float m_animationTime;
    
    // === 背景效果 ===
    QList<QPointF> m_particlePositions;
    QList<QPointF> m_particleVelocities;
    QList<QColor> m_particleColors;
    QList<float> m_particleSizes;
    
    // === 玩家信息 ===
    QString m_playerId;
    QString m_playerName;
};

#endif // MODERNSNAKEENTRYWIDGET_H
